import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
	const envConfig = loadEnv(mode, './');
	console.log('============================= 当前环境配置 =============================');
	console.log(envConfig);
	console.log('============================= 当前环境配置 =============================');
	return {
		base: './',
		plugins: [
			vue(),
			Components({
				resolvers: [
					AntDesignVueResolver({
						// 这个要去掉，要不然按需引入的样式会覆盖掉我们自定义设置的
						importStyle: false,
					}),
				],
			}),
		],
		resolve: {
			alias: {
				'@': path.resolve(__dirname, 'src'),
			},
		},
		css: {
			preprocessorOptions: {
				less: {
					modifyVars: {
						hack: `true; @import "ant-design-vue/dist/antd.variable.less"; @import "@/styles/common.less";`,
					},
					javascriptEnabled: true,
				},
			},
		},
		build: {
			target: 'es2015',
		},
		server: {
			host: '0.0.0.0',
			port: 9527,
			open: true,
		},
	};
});
